package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	pb "grpc_demo/grpc_error/grpc_error"
	"net"
)

func main() {

	g := grpc.NewServer()
	s := server{}
	pb.RegisterGreeterServer(g, &s)
	lis, err := net.Listen("tcp", fmt.Sprintf(":8088"))
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("start server")
	g.Serve(lis)
}

type server struct {
	pb.UnimplementedGreeterServer
}

func (s *server) SayHello(ctx context.Context, req *pb.HelloRequest) (res *pb.HelloReply, err error) {
	return &pb.HelloReply{Message: "hello" + req.Name}, nil
}

func (s *server) SayHelloAgain(ctx context.Context, req *pb.HelloRequest) (res *pb.HelloReply, err error) {
	return &pb.HelloReply{Message: "hello" + req.Name}, nil
}
